package com.shujia.scala

import scala.io.Source

object Demo30Implicit {
  def main(args: Array[String]): Unit = {
    /**
     * 2、隐式转换类
     *
     */

    val path: String = "data/students.txt"
    //val lines: List[String] = Source.fromFile(path).getLines().toList

    //val read = new Read(path)
    //val strings: List[String] = read.read()

    //使用隐式转换动态增加的方法
    val students: List[String] = path.read()
    println(students)

    val scores: List[String] = "data/score.txt".read()
    println(scores)


  }

  /**
   * 隐式转换类： 可以隐式将类的构造函数参数类型转换类的类型
   * String转换成Read类型
   */
  implicit class Read(path: String) {
    def read(): List[String] = {
      Source.fromFile(path).getLines().toList
    }
  }

}
